How To Properly Deal With Dynamically Allocated Memory